package com.edu.exam.enums.questionbank;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 评分规则状态枚举
 *
 * 管理选择题评分规则的状态，包括草稿、激活、禁用等状态
 *
 * @author System
 * @version 1.0.0
 */
public enum ScoringRuleStatus implements BaseEnum {

    /**
     * 草稿
     */
    DRAFT("DRAFT", "草稿"),

    /**
     * 激活
     */
    ACTIVE("ACTIVE", "激活"),

    /**
     * 禁用
     */
    DISABLED("DISABLED", "禁用");

    private final String code;
    private final String description;

    ScoringRuleStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static ScoringRuleStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("ScoringRuleStatus code cannot be null or empty");
        }
        for (ScoringRuleStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown scoring rule status code: " + code);
    }

    public static ScoringRuleStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("ScoringRuleStatus description cannot be null or empty");
        }
        for (ScoringRuleStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown scoring rule status description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}